# Maintainer: Florian Pritz <bluewind@xinu.at>
pkgname=grafana-zabbix
pkgver=4.3.1
pkgrel=1
pkgdesc="Zabbix plugin for Grafana dashboard"
arch=('any')
url="https://github.com/alexanderzobnin/grafana-zabbix"
license=('APACHE')
depends=('grafana')
makedepends=(yarn libfaketime go git nodejs-lts-gallium mage)
source=("$pkgname-$pkgver-retagged-1.tar.gz::https://github.com/alexanderzobnin/grafana-zabbix/archive/v$pkgver.tar.gz")
sha256sums=('e1871012afd502434eb716fa0c2337618f98987e4ed2893c96c283d5a7ed2ddb')

prepare() {
	cd "$pkgname-$pkgver"

	# Fix tests not working without git clone
	sed -i 's#jest --watch --onlyChanged#jest#' package.json
}

build() {
	cd "$pkgname-$pkgver"
	make install
	make build
	make dist
}

check() {
	cd "$pkgname-$pkgver"
	# Force UTC timezone so that tests pass, even after a DST change
	PATH="$PATH:/build/go/bin" TZ=UTC make test lint
}

package() {
	cd "$pkgname-$pkgver"
	install -dm755 "$pkgdir/var/lib/grafana/plugins/alexanderzobnin-zabbix-app"
	cp -r dist/* "$pkgdir/var/lib/grafana/plugins/alexanderzobnin-zabbix-app"
	rm -rf "$pkgdir/var/lib/grafana/plugins/alexanderzobnin-zabbix-app/node_modules"
}
